/* 
  Copyright (c) SilverLining 2015
  Date:    2016-1-7
  File:    Game.h  
  Description: 
  Header for the game object.
*/

#pragma once

namespace SL
{
	namespace M
	{
		/// <summary>
		/// Contains most of the core managed code for the M project.
		/// </summary>

		ref class Process;
		ref class MessageType;

		/// <summary>
		/// Represent the central game state object.
		/// </summary>
		/// <remarks>This class is similar in functionality to the process_manager native class.</remarks>
		public ref class Game
		{
		public:
			Game();
			~Game();
			!Game();

			/// <summary>
			/// Add a process to the game session and automatically start it.
			/// </summary>
			/// <param name="process">The process to add.</param>
			void AddProcess(Process^ process);
			/// <summary>
			/// Remove a process from the game session.
			/// </summary>
			/// <param name="process">The process to remove.</param>
			/// <remarks>The process must handle a MONO_STOP message before it can be removed.</remarks>
			bool RemoveProcess(Process^ process);

			/// <summary>
			/// Start the game session.
			/// </summary>
			/// <remarks>You must call this before adding any processes.</remarks>
			void Start();
			/// <summary>
			/// Stop the game session, removing all processes from it.
			/// </summary>
			void Stop();

			/// <summary>
			/// Pause the game session, suspending message dispatch.
			/// </summary>
			void Pause();
			/// <summary>
			/// Resume the game session, allowing message dispatch to continue.
			/// </summary>
			void Resume();
			/// <summary>
			/// Flush any outstanding messages in the process message buffer.
			/// </summary>
			/// <remarks>This is intended for debugging only.</remarks>
			void Flush();

			/// <summary>
			/// Represent the managed process list for the game.
			/// </summary>
			property ICollection<Process^>^ Processes
			{
				/// <summary>
				/// Return the process list for the game
				/// </summary>
				/// <returns>A list of processess.</returns>
				ICollection<Process^>^ get();
			}

			/// <summary>
			/// Represent the game status.
			/// </summary>
			property bool Started
			{
				/// <summary>
				/// Return if the game was started.
				/// </summary>
				/// <returns>A boolean value.</returns>
				bool get();
			}

			/// <summary>
			/// Represent the resumed status of the game.
			/// </summary>
			property bool Resumed
			{
				/// <summary>
				/// Return if the game was not paused.
				/// </summary>
				/// <returns>A boolean.</returns>
				bool get();
			}

		internal:
			m::process_manager* _ProcessManager;
			m::package_manager* _PackageManager;
			m::io::file_streamer* _FileStreamer;
			m::alloc::pool_cleaner* _PoolCleaner;

		private:
			Object^ _processLock;
			List<Process^>^ _processes;
		};
	}
}